Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax: fix flag scoping issue #641

Merged
merged 1 commit into from
Jan 30, 2020
Merged

syntax: fix flag scoping issue #641

merged 1 commit into from
Jan 30, 2020

Conversation

BurntSushi
Copy link
Member

This fixes a rather nasty bug where flags set inside a group were being
applies to expressions outside the group. e.g., In the simplest case,
((?i)a)b) would match aB, even though the case insensitive flag
shouldn't be applied to b.

The issue here was that we were actually going out of our way to reset
the flags when a group is popped only some of the time. Namely, when
flags were set via (?i:a)b syntax. Instead, flags should be reset to
their previous state every time a group is popped in the translator.

The fix here is pretty simple. When we open a group, if the group itself
does not have any flags, then we simply record the current state of the
flags instead of trying to replace the current flags. Then, when we pop
the group, we are guaranteed to obtain the old flags, at which point, we
reset them.

Fixes #640

This fixes a rather nasty bug where flags set inside a group were being
applies to expressions outside the group. e.g., In the simplest case,
`((?i)a)b)` would match `aB`, even though the case insensitive flag
_shouldn't_ be applied to `b`.

The issue here was that we were actually going out of our way to reset
the flags when a group is popped only _some_ of the time. Namely, when
flags were set via `(?i:a)b` syntax. Instead, flags should be reset to
their previous state _every_ time a group is popped in the translator.

The fix here is pretty simple. When we open a group, if the group itself
does not have any flags, then we simply record the current state of the
flags instead of trying to replace the current flags. Then, when we pop
the group, we are guaranteed to obtain the old flags, at which point, we
reset them.

Fixes #640
@BurntSushi BurntSushi merged commit ea4009a into master Jan 30, 2020
@BurntSushi BurntSushi deleted the ag/fix-flag-unset branch January 30, 2020 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flag effect remains active outside of current group
1 participant